<template>
  <div class="form-layout form-layout4">
    <!--左侧导航-->
    <div class="nav-left">
      <customAnchor :itemList="[
        { name: 'box-base', title: '记账信息' },
        { name: 'box-dtl', title: '记账明细' }]" />
    </div>
    <!--表单区域-->
    <div class="form-right" ref="formRight">
      <customForm :data="form" :rules="propRules" ref="editForm" :disabled="propReadonly">
        <template #content>
          <div id="box-base" class="box-title">记账信息</div>
          <customFormItem label="记帐单号" name="code" :parent="_self" :form="form" />
          <customFormItem label="记账日期" name="gmtBill" :parent="_self" :form="form" />
          <customFormItem
            label="记账类型"
            name="msgType"
            :parent="_self"
            :form="form"
            :type="constCommon.formItemType.slot.name"
          >
            <template #content>
              <span  v-html="utils.getBooleanLabel(form.isConsignment,'代销', '购销')">
              </span>

              <span style="margin: 0px 5px 0px 5px" v-html="utils.getBooleanLabel(form.isOneThingOneYard,'标签管理', '非标签管理')">
              </span>
            </template>
          </customFormItem>
          <customFormItem label="医院" name="hospitalName" :parent="_self" :form="form" />
          <customFormItem label="供应商" name="supplierName" :parent="_self" :form="form" />
          <customFormItem label="金额" name="totalAmount" :parent="_self" :form="form" />
          <customFormItem label="状态" name="status" :parent="_self" :form="form"
                          :type="constCommon.formItemType.inputNumber.name"
                          :config="{dictType: constCommon.dictType.settlementBillStatus}"
          />
          <customFormItem label="结算期号" name="periodNo" :parent="_self" :form="form" />
          <customFormItem label="结算时间" name="gmtSettlement" :parent="_self" :form="form" />
          <customFormItem label="备注" name="remark" :parent="_self" :form="form" />


          <div id="box-dtl" class="box-title">记账明细</div>
          <data-view
            propViewKey="bill_item_index"
            :propIsTdesign="true"
            :propParentPage="_self"
            ref="childDataView"
            :propAutoFetchData="false"
            :propTableHide="!form.id"
            :propOnlyQueryAll="propReadonly"
            :propInitData="form"
          />
        </template>
      </customForm>
    </div>
  </div>
</template>

<script>
import customAnchor from '@/components/custom/form/customAnchor.vue'


export default {
  help: '记账-详情',
  data() {
    return {
      form: {},
      viewData: {},
    }
  },
  methods: {
    // 加载明细数据
    fetchChildData() {
      let queryWrapper = this.$newWrapper()
      if (this.form.id) {
        queryWrapper.eq('billId', this.form.id)
      } else {
        queryWrapper.ne(1, 1)
      }
      this.$refs.childDataView.setQueryWrapper(queryWrapper)
    },
  },
  created() {
    this.$emit('event-register', {
      validate: (callback) => {
        return this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        this.$emit('data-callback', this.form)
        return true
      },
      afterMove: (formData) => {
        this.form = global.utils.jsonClone(formData)
        this.$set(this.form, 'id', this.form.id)
        this.fetchChildData()
      },
      afterSave: () => {
      },
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {
      },
      beforeFlow: (flowButtonKey) => {
        return true
      },
      afterFlow: (flowButtonKey) => {
      },
      beforeClose: () => {
        return true
      },
    })
  },
  props: {
    propParent: Object,
    propInitData: Object,
    propPrimaryKey: String,
    propDictionaries: Object,
    propCurrentRow: Object,
    propViewFormData: Object,
    propReadonly: Boolean,
    propStatus: String,
    propRules: Object,
  },
  components: { customAnchor},
  computed: {
  },
}
</script>
